<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<script type="text/javascript"
	src="${webroot}/static/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript"
	src="${webroot}/static/js/bootstrap.min.js"></script>
<script type="text/javascript"
	src="${webroot}/static/js/bootstrap-table.js"></script>
<script type="text/javascript"
	src="${webroot}/static/js/app-common-2.00.0.js"></script>
<script type="text/javascript" src="${webroot}/static/js/layer/layer.js"></script>
<script src="${webroot}/static/js/jquery.form.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css"
	href="${webroot}/static/js/layer/skin/layer.css" />
<link rel="stylesheet" type="text/css"
	href="${webroot}/static/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css"
	href="${webroot}/static/css/bootstrap-table.min.css" />
<link rel="stylesheet" type="text/css" href="${webroot}/static/css/forms.css" />
<html lang="en">
<head>
<style type="text/css">
  .layui-btn-sms {
    height: 25px;
    line-height: 19px;
    padding: 0 10px;
    font-size: 12px;
    width: 56px;
    background-color: white;
    color: #000000e0;
    border: 0.5px solid #000000e0;
}
.table>tbody>tr>td, .table>tfoot>tr>td {
    text-align: center;
    vertical-align: middle;
}
.table>tbody>tr:hover{background-color:#197daa; }

</style>
</head>
<body>
	<div>
		<form class="order-form" id="filterForm">
			<input type="hidden" id="tg" name="tg" /> <input type="hidden"
				id="btg" name="btg" /> <input type="hidden" id="ft" name="ft" />
				<input type="hidden" id="jf" name="jf" />
			<div class="control-group clearfix" style="width: 15%;">
				<label>状态:</label>
				<div class="control">
					<select id="status" class="control-select">
						<option value="">请选择</option>
						<option value="0">审核中</option>
						<option value="1">审核失败</option>
						<option value="2">审核成功</option>
					</select>
				</div>
			</div>
			<div class="control-group clearfix" style="width: 15%;">
				<div class="control">
				   <input type="button" value="查询" id="btn_query" class="layui-btn layui-btn-sm layui-btn-normal"/>&nbsp;
			       <input type="button" value="重置" id="btn_reunion" class="layui-btn layui-btn-sm layui-btn-danger"/>
				</div>
			</div>
		</form>
		<div style="padding-top: 38px;">
		</div>
		<form id='dictGridDiv'></form>
	</div>
</body>
<script type="text/javascript">
var list = JSON.parse('${gpLists}');
for (var i = 0; i < list.length; i++) {
	if(list[i].resourceName=="通过"){
		$("#tg").val("1");
	}
	if(list[i].resourceName=="不通过"){
		$("#btg").val("1");
	}
	if(list[i].resourceName=="封团"){
		$("#ft").val("1");
	}
	if(list[i].resourceName=="解封"){
		$("#jf").val("1");
	}
}
	$(function() {
		//1.初始化Table
		var oTable = new TableInit();
		oTable.Init();
		$("#btn_query").click(function() {
			$("#dictGridDiv").bootstrapTable('destroy');
			var oTable = new TableInit();
			oTable.Init();
		});
		$("#btn_reunion").click(function() {
			$("#status").val("");
			$("#dictGridDiv").bootstrapTable('destroy');
			var oTable = new TableInit();
			oTable.Init();
		});
	});
	var TableInit = function() {
		var oTableInit = new Object();
		//初始化Table
		oTableInit.Init = function() {
			$('#dictGridDiv')
					.bootstrapTable(
							{
								url : '${webroot}/agent/querypagelist',
								dataType : "json",
								toolbar : '#toolbar', //工具按钮用哪个容器
								striped : true, //是否显示行间隔色
								singleSelect : false,
								pagination : true, //分页
								pageNumber : 1, //初始化加载第一页，默认第一页
								queryParams : queryParams,
								pageSize : 10, //每页的记录行数（*）
								pageList : false, //可供选择的每页的行数（*）
								//search: true, //显示搜索框
								sidePagination : "server", //服务端处理分页
								columns : [
										{
											field : 'seqon',
											title : '序号',
											align : 'center',
											width : '50'
										},
										{
											field : 'groupName',
											title : '团队名称',
											align : 'center',
											width : '85'
										},
										{
											field : 'nickname',
											title : '昵称',
											align : 'center',
											width : '105'
										},
										{
											field : 'name',
											title : '姓名',
											align : 'center',
											width : '80'
										},
										{
											field : 'phone',
											title : '手机号',
											align : 'center',
											width : '105'
										},
										{
											field : 'wechar',
											title : '微信号',
											align : 'center',
											width : '115'
										},
										{
											field : 'groupIntroduce',
											title : '个人介绍',
											align : 'center',
											width : '888'
										},
										{
											field : 'agentProduct',
											title : '代理产品',
											align : 'center',
											width : '165'
										},
										{
											field : 'status',
											title : '状态',
											align : 'center',
											width : '90',
											formatter : function(value, row,index) {
												if(value == '0'){
													return "未审核";
												}else if(value == '1'){
													return "不通过";
												}else if(value == '2'){
													return "通过";
												}
											}
										},
										{
											title : '选项',
											align : 'center',
											width : '220',
											formatter : function(value, row,index) {
												var str = "";
												if($("#tg").val() == '1'){
													if ( row.status == '0') {
														str += '<input type="button" value="通过" class="layui-btn layui-btn-primary layui-btn-sms" onclick="upFeed(\''+ row.id + '\',\''+ row.groupName + '\',2)" /> &nbsp&nbsp';
													}
												}
												if($("#btg").val() == '1'){
													if (row.status == '0') {
														str += '<input type="button" value="不通过" class="layui-btn layui-btn-primary layui-btn-sms" onclick="upFeed(\''+ row.id + '\',\''+ row.groupName + '\',1)" /> &nbsp&nbsp';
													}else if(row.status == '1'){
														str += '<input type="button" value="通过" class="layui-btn layui-btn-primary layui-btn-sms" onclick="upFeed(\''+ row.id + '\',\''+ row.groupName + '\',2)" /> &nbsp&nbsp';
													}
												}
												if($("#ft").val() == '1'){
													if (row.status == '2' && row.selectd == '0') {
													    str += '<input type="button" value="封团" class="layui-btn layui-btn-primary layui-btn-sms" onclick="dlFeed(\''+ row.id + '\',\''+ row.groupName + '\',1)" />';
													}
												}
												if($("#jf").val() == '1'){
													if (row.status == '2' && row.selectd == '1') {
													    str += '<input type="button" value="解封" class="layui-btn layui-btn-primary layui-btn-sms" onclick="dlFeed(\''+ row.id + '\',\''+ row.groupName + '\',0)" />';
													}
												}
												return str;
											}
										} ]
							});
		};
		function queryParams(params) {
			return {
				pageSize : params.limit, //页面大小
				pageNumber : params.offset, //页码
				status : $('#status option:selected').val()
			};
		}
		return oTableInit;
	};

	//新增 - 修改
	function Add(roleId) {
		window.location.href = '${webroot}/feedback/detail?roleId=' + roleId;
	}

	
	function upFeed(id,groupName,i) {
		var title ="";
		if(i == "1"){
			title ="不通过";
	    }else{
	    	title ="通过";
	    }
		layer.confirm('确定要'+title+'吗?', function() {
			//调用ajax局部启动
			$.ajax({
				url : "${webroot}/agent/update",
				type : "POST",
				data : {
					"id" : id,
					"groupName" : groupName,
					"status" : i
				},
				dataType : "json",
				async : false,
				cache : false,
				success : function(obj) {
					if (obj != null) {
						if (obj.success) {
							layer.msg("操作成功");
						} else {
							layer.msg("操作失败");
						}
					}
				}
			});
			$("#dictGridDiv").bootstrapTable('destroy');
			var oTable = new TableInit();
			oTable.Init();
		});
	}
	
	function dlFeed(id,groupName,i) {
		var title ="";
		if(i == "1"){
			title ="封团";
	    }else{
	    	title ="解封";
	    }
		layer.confirm('确定要'+title+'吗?', function() {
			//调用ajax局部启动
			$.ajax({
				url : "${webroot}/agent/update",
				type : "POST",
				data : {
					"id" : id,
					"groupName" : groupName,
					"selectd" : i
				},
				dataType : "json",
				async : false,
				cache : false,
				success : function(obj) {
					if (obj != null) {
						if (obj.success) {
							layer.msg("操作成功");
						} else {
							layer.msg("操作失败");
						}
					}
				}
			});
			$("#dictGridDiv").bootstrapTable('destroy');
			var oTable = new TableInit();
			oTable.Init();
		});
	}
	
	//批量删除
	function delAll(){
		var ss= "";
		$.each($('input:checkbox'),function(){
	        if(this.checked){
	           ss += $(this).attr("id")+",";
	        }
	    });
		$.ajax({
			url : "${webroot}/feedback/delete",
			type : "POST",
			dataType : "json",
			async : false,
			data:{
			   'id' : ss
			},
			cache : false,
			success : function(obj) {
				if (obj != null) {
					layer.msg("操作成功");
					$("#mainLeftDiv").empty();
					setTimeout(select(),1000);
				}else{
					layer.msg("操作失败");
				}		
			}
		})
		$("#dictGridDiv").bootstrapTable('destroy');
		var oTable = new TableInit();
		oTable.Init();
	}
</script>
</html>